import logging
import os

from facade.loggerfacade import get_filelogger
from xjlibrary.our_file_dir import BaseDir

nCount = 0
cur_path = BaseDir.get_file_dir_absolute(__file__)
TopPath = BaseDir.get_upper_dir(cur_path, -3)
# coverPath = BaseDir.get_new_path(TopPath, "download", "TandfJournal", "cover")
coverPath = r"\\192.168.30.177\样例数据\tandfjournal\tandfjournal_cover"
# 转换成base32编码
logger = None


def main(logger1: logging.Logger):
    global logger
    logger = logger1
    nCount = 0
    provider = 'tandfjournal'
    filePath = provider + '_cover.txt'
    filePath = BaseDir.get_new_path(r"\\192.168.30.177\样例数据\tandfjournal", filePath)
    print('path:' + coverPath)

    with open(filePath, mode='w', encoding='utf-8') as f:
        for path, dirNames, fileNames in os.walk(coverPath):
            for fileName in fileNames:
                # 分离文件名与扩展名 返回文件名和扩展名
                journal = os.path.splitext(fileName)[0]
                line = provider + '@' + journal + '★/smartlib/' + provider + '/' + fileName + '\n'
                f.write(line)
                nCount += 1
    print('nCount:' + str(nCount))


if __name__ == "__main__":
    logger1 = get_filelogger("./logs")
    main(logger1)
